package com.xszx.servlet.admin.shop;

import com.xszx.bean.Goods;
import com.xszx.dao.GoodsDao;
import com.xszx.dao.impl.GoodsDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@WebServlet("/AddShopServlet")
public class AddGoodsServlet extends HttpServlet {
    static GoodsDao goodsDao = new GoodsDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String goodsName = req.getParameter("goodsName");
        Double goodsPrice = Double.parseDouble(req.getParameter("goodsPrice"));
        String goodsImageUrl = req.getParameter("goodsImageUrl");
        String goodsInfo = req.getParameter("goodsInfo");
        Integer goodsType = Integer.parseInt(req.getParameter("goodsType"));

        Goods goods = new Goods(goodsName, goodsPrice, goodsImageUrl, null, 2, goodsInfo, goodsType);
        goodsDao.addGoods(goods);
        resp.sendRedirect("GetAllGoodsServlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
